<?php
session_start();
$link = mysql_connect("localhost", "rene_fotoclub", "kroog") or die("Keine Verbindung moeglich: " . mysql_error());
mysql_select_db("rene_fotoclub") or die("Auswahl der Datenbank fehlgeschlagen");
header('Content-Type: text/plain');
//if(isset($_SESSION['user']){
//echo "hier bin ich '".$_REQUEST['func']."','".$_REQUEST['goal']."',".$_SESSION['user'];
if($_REQUEST['func'] == "theme"){
	if($_REQUEST['goal'] == "add"){
		//echo "INSERT INTO theme (tag,userid,inserted, times) VALUES('".$_REQUEST['newtheme']."',".$_SESSION['user'].",CURDATE(), 0)";
		mysql_query("INSERT INTO theme (tag,userid,inserted, times) VALUES('".$_REQUEST['newtheme']."',".$_SESSION['user'].",CURDATE(), 0)") or die("Anfrage fehlgeschlagen: " . mysql_error());
	}
	elseif($_REQUEST['goal'] == "load"){
		echo "{ \"identifier\": \"id\", \"label\": \"tag\", \"items\": [";
		$themeList = mysql_query("SELECT t.tag, u.name as user, t.times, t.inserted from theme t, user u where t.userid = u.id order by t.tag asc")  or die("Anfrage fehlgeschlagen: " . mysql_error());
		$cnt = mysql_num_rows($themeList);
		$i = $cnt;
		while ($row = mysql_fetch_assoc($themeList)) {
			$i--;
			echo "{ \"tag\":\"".$row['tag']."\", \"user\":\"".$row['user']."\", \"times\":\"".$row['times']."\",\"inserted\":\"".$row['inserted']."\"}";
			if($i>0)
			echo ",";
		}
		echo "] }";
	}

}
?>